﻿using Grpc.Net.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using ScienceRpcServe.Protos;
using static ScienceRpcServe.Protos.HistoryImageRecord;

namespace ScienceAppService.RpcUtils;
public class RpcConfigure
{

    private readonly GrpcChannel _channel;

    private ImageShow.ImageShowClient _imageShowClient;

    private ArmBoneSeg.ArmBoneSegClient _armBoneSegClient;

    private DicomSplit.DicomSplitClient _dicomSplitClient;

    private HistoryImageRecord.HistoryImageRecordClient _historyImageRecordClient;

    #region Singleton 懒加载单例模式
    private RpcConfigure()
    {
        _channel = GrpcChannel.ForAddress("http://127.0.0.1:5001", new GrpcChannelOptions
        {
            MaxReceiveMessageSize = 15 * 1024 * 1024,
        });
    }
    private static readonly Lazy<RpcConfigure> Lazy = new(() => new RpcConfigure());
    public static RpcConfigure Instance => Lazy.Value;
    #endregion

    public ImageShow.ImageShowClient GetImageShowClient()
    {
        return _imageShowClient ??= new ImageShow.ImageShowClient(_channel);
    }

    public ArmBoneSeg.ArmBoneSegClient GetArmBoneSegClient()
    {
        return _armBoneSegClient ??= new ArmBoneSeg.ArmBoneSegClient(_channel);
    }

    /// <summary>
    /// 获取DicomSplit 客户端
    /// </summary>
    /// <returns></returns>
    public DicomSplit.DicomSplitClient GetDicomSplitClient()
    {
        return _dicomSplitClient ??= new DicomSplit.DicomSplitClient(_channel);
    }

    public HistoryImageRecordClient GetHistoryImageRecordClient()
    {
        return _historyImageRecordClient ??= new HistoryImageRecord.HistoryImageRecordClient(_channel);
    }

}
